package zookeeper.lock;

/**
 * @author Arnold Yand
 * @summary
 * @time 2018/4/15 11:08
 */
public class ZookeeperLockTest {

  public void tryLock() throws Exception {
    ZookeeperDistributedLock zkdl = new ZookeeperDistributedLock("127.0.0.1:2181", "/etl", 10000);
    zkdl.lock();
//    TimeUnit.SECONDS.sleep(10);
    if(zkdl != null){zkdl.unlock();}
  }

  public static void main(String[] args) {
    for(int i = 0 ; i< 3;i++){
      new Thread(new Runnable() {
        @Override
        public void run() {
          try{
            ZookeeperDistributedLock zkdl = new ZookeeperDistributedLock("127.0.0.1:2181", "/etl", 10000);
            zkdl.lock();
//            TimeUnit.SECONDS.sleep(10);
            if(zkdl != null){zkdl.unlock();}
          }catch (Exception e){
            e.printStackTrace();
          }
        }
      }).start();
    }
  }
}
